/**      
 * @file		strncpy.cpp
 * @description	This example utilizes strncpy() to copy
 *				one cstring to another. strncpy has an additional
 *				parameter that determines how many characters to copy
 *				to the destination.
 * @course		CSCI 123 Section 00000
 * @assignment 
 * @date		mm/dd/yyyy
 *  @author		Brad Rippe (00000000) brippe@fullcoll.edu
 * @version		1.0
 */
#include <iostream>
#include <cstring>
using namespace std;

/**
 * @return zero if the application executes successfully
 */
int main() {
	char cString1[] 	= "Please email my message to the class!";
	char cString2[] 	= "";
	int cString1Size 	= 0;

	// get the size of cString1
	// we could use strlen(cString1) also
	while(cString1[cString1Size] != '\0') cString1Size++;

	cout << "This application demonstrates how to copy cstrings\n";
	cout << "Remember we can't use the assignment operator, = to assign";
	cout << " cstrings values unless we use it when we declare the cstring\n";
	cout << "Here is a sample of strcpy()\n";
	cout << "cString1 = " << cString1 << endl;
	cout << "cString2 = " << cString2 << endl;
	cout << "Now we'll use strncpy(destination, source, charsToCopy) to copy cString1 to cString2\n";
	cout << "strncpy(cString2, cString1, charsToCopy);\n";
	strncpy(cString2, cString1, cString1Size);
	cout << "cString1 = " << cString1 << endl;
	cout << "cString2 = " << cString2 << endl;
	// What happens with this code?
	// On my machine, both variables get allocated memory
	// cString2 only gets allocated enough memory for an empty string
	// cString1 is given the memory after cString2
	// when cString1 is copied to cString2, it overwrites part of 
	// cString1 this is bad

	return 0;
}

